<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title a m-cf">店员列表</div>
                </div>
                <div class="widget-body am-fr">
                    <!-- 工具栏 -->
                    <div class="page_toolbar am-margin-bottom am-cf">
                        <form class="toolbar-form">
                            <div class="am-u-sm-12 am-u-md-3">
                                <div class="am-form-group">
                                    <div class="am-btn-group am-btn-group-sm">
                                        <a href="javascript:void(0);" class="hema-add am-btn am-btn-primary am-radius">
                                            <span class="am-icon-plus"></span> 添加
                                        </a>
                                    </div>
                                </div>
                            </div>
                            <div class="am-u-sm-12 am-u-md-9">
                                <div class="am fr">
                                    <div class="am-form-group am-fl">
                                        <div class="am-input-group am-input-group-sm tpl-form-border-form">
                                            <input type="text" class="am-form-field" name="search"
                                                   placeholder="请输入店员姓名/手机号" value="{$search}">
                                            <div class="am-input-group-btn">
                                                <button class="am-btn am-btn-default am-icon-search" type="submit"></button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="am-scrollable-horizontal am-u-sm-12">
                        <table width="100%" class="am-table am-table-hover tpl-table-black">
                            <thead>
                            <tr>
                                <th>编号ID</th>
                                <th>姓名</th>
                                <th>手机号</th>
                                <th>身份</th>
                                <th>微信提醒</th>
                                <th>添加时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {if !$list->isEmpty()}
                                {foreach $list as $item}
                                <tr>
                                    <td class="am-text-middle">{$item['shop_clerk_id']}</td>
                                    <td class="am-text-middle"><p>{$item['linkman']}</p></td>
                                    <td class="am-text-middle">{$item['phone']}</td>
                                    <td class="am-text-middle">
										<span class="am-badge {$item['status']['value']==20 ? ' am-badge-warning' : ' am-badge-success'}">
										{$item['status']['text']}
										</span>
                                    </td>
                                    <td class="am-text-middle">
                                        {if $item['wx_open_id']!=''}
                                        <a href="javascript:;" class="hema-wechat-bind am-badge am-badge-success" data-id="{$item['shop_clerk_id']}" data-name="{$item['linkman']}">更换</a>
										{else /}
										<a href="javascript:;" class="hema-wechat-bind am-badge" data-id="{$item['shop_clerk_id']}" data-name="{$item['linkman']}">绑定</a>
										{/if}
                                    </td>
                                    <td class="am-text-middle">{$item['create_time']}</td>
                                    <td class="am-text-middle">
                                        <div class="tpl-table-black-operation">
                                            <a href="javascript:;" class="hema-edit" data-id="{$item['shop_clerk_id']}">
                                                <i class="am-icon-pencil"></i> 编辑
                                            </a>
                                            <a href="javascript:;" class="hema-del tpl-table-black-operation-del"
                                               data-id="{$item['shop_clerk_id']}">
                                                <i class="am-icon-trash"></i> 删除
                                            </a>
                                        </div>
                                    </td>
                                </tr>
                                {/foreach}
                            {else /}
                                <tr>
                                    <td colspan="7" class="am-text-center">暂无记录</td>
                                </tr>
                            {/if}
                            </tbody>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">
                        <div class="am-fr">{:$list->render()} </div>
                        <div class="am-fr pagination-total am-margin-right">
                            <div class="am-vertical-align-middle">总记录：{:$list->total()}</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="shop/clerk/add" /}
{include file="shop/clerk/edit" /}
{include file="layout/wechat" /}
<script>
    $(function () {
        //关注公众号登录
        $('.hema-wechat-bind').on('click', function () {
            var data = $(this).data();
            $.get("/admin/passport/qrcodeCreate", function (result) {
				if(result.code == 0){
				    $.show_error(result.msg);
				    return false;
				}
                $.showAction({
                    title: '店员《'+data.name+'》绑定微信', 
                    area: '400px', 
                    content: template('tpl-wechat-bind', result.data), 
                    uCheck: true, 
                    btn: ['取消'],
                    success: function ($content) {
                        //关注公众号登录
                        var interval = setInterval(function(){
                            $.post("/admin/passport/checklogin",{
                                ticket:result.data.ticket
                            },function(res){
                                if(res.code == 1){
                                    $.post("{:url('shop.clerk/wechatBind')}?id="+data.id,{
                                        data:res.data
                                    },function(rs){
                                        if(rs.code == 1){
                                            window.location.reload();
                                            return true;
                                        }else{
                                            $.show_error(rs.msg);
				                            return false;
                                        }
                                    });
                                }
                            });
                        },3000);
                    }, 
                    btn2: function ($content) {
                        return true;
                    }
                });
            });
        });
         //添加
        $('.hema-add').on('click', function () {
            $.showAction({
                title: '添加', 
                area: '750px', 
                content: template('tpl-add', {}), 
                uCheck: true, 
                success: function ($content) {
                    $('#my-form').formPost({
                        url: "{:url('shop.clerk/add')}"
                    });
                }, 
                btn2: function ($content) {
                    return true;
                }
            });
        });
        //编辑
        $('.hema-edit').on('click', function () {
            var data = $(this).data();
            $.get("{:url('shop.clerk/edit')}?id=" + data.id, function (result) {
				if(result.code == 0){
				    $.show_error(result.msg);
				    return false;
				}
				$.showAction({
                    title: '编辑', 
                    area: '750px', 
                    content: template('tpl-edit', {model:result.data.model}), 
                    uCheck: true, 
                    success: function ($content) {
                        $('#my-form').formPost({
                            url: "{:url('shop.clerk/edit')}?id=" + data.id
                        });
                    }, 
                    btn2: function ($content) {
                        return true;
                    }
                });
            });
        });
        // 删除元素
        var url = "{:url('shop.clerk/delete')}";
        $('.hema-del').del('id', url);

    });
</script>

